function retry(promiseFunction, timeLimit) {
  let arr = [];
  while (timeLimit--) {
    arr.push(promiseFunction());
  }
  return Promise.any(arr);
}

function PromiseFunction() {
  let random = Math.random();
  if (random >= 1) {
    return Promise.resolve("success");
  } else {
    return Promise.reject("fail");
  }
}
retry(PromiseFunction, 3)
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.log(err);
  });
